package com.imti.util;

import java.util.*;

public class RandomUtils {
    /**
     * 生成n个不重复的指定范围的随机整数
     * @param n 随机数个数
     * @param min 最小值
     * @param max 最大值
     * @return 随机数列表
     */
    public static List<Integer> generateRandomIntegers(int n, int min, int max) {
        if (max - min + 1 < n) {
            throw new IllegalArgumentException("Invalid range or count");
        }

        Set<Integer> randomIntegers = new HashSet<>();
        Random random = new Random();

        while (randomIntegers.size() < n) {
            int randomNum = random.nextInt(max - min + 1) + min;
            randomIntegers.add(randomNum);
        }
        List<Integer> shuffledList = new ArrayList<>(randomIntegers);
        Collections.shuffle(shuffledList);
        return shuffledList;
    }
}
